Namespace Workflow

    Partial Class UCList
        Inherits System.Web.UI.UserControl

#Region " Web Form Designer Generated Code "

        'This call is required by the Web Form Designer.
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

        End Sub


        Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
            'CODEGEN: This method call is required by the Web Form Designer
            'Do not modify it using the code editor.
            InitializeComponent()
        End Sub

#End Region
        Private m_url As String
        Private m_desc As Boolean

        Public Function GetSortByUrl(sortBy As String) As String
            Return Url(sortBy)
        End Function
        Public Function Url(sortBy As String) As String
            Return Url(sortBy, Not m_desc)
        End Function
        Public Function Url(sortBy As String, desc As Boolean) As String
            Return String.Concat(m_url, "&sort=", HttpUtility.UrlEncode(sortBy), "&desc=", desc)
        End Function


        Public Sub Display(s As String, assignedTo As Integer, categoryId As Integer, status As Integer, ByVal priorityId As Integer, url As String, sortBy As String, desc As Boolean)
            m_url = url
            m_desc = desc

            Dim items As CItemList = CItem.Cache.Search(s, assignedTo, categoryId, status, priorityId, CConfig.StatusComplete)
            If Not String.IsNullOrEmpty(sortBy) Then
                items = items.SortBy(sortBy, desc)
            End If

            Me.Visible = items.Count > 0
            If Not Me.Visible Then Exit Sub

            dgItems.DataSource = items
            dgItems.DataBind()

            Dim i As CItem
            Dim total As Double = 0
            For Each i In items
                total += i.ItemEstimatedHours
            Next
            litTotal.Text = total


            litPriorityName.Text = CPriority.Cache.GetById(priorityId).PriorityName
        End Sub

        Protected Sub dgItems_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgItems.ItemDataBound
            Dim plh As PlaceHolder = e.Item.FindControl("plh")
            Dim item As CItem = e.Item.DataItem
            If IsNothing(item) Then Exit Sub

            'For Each i As CComment In item.Comments
            '    Dim div As New HtmlGenericControl("div")
            '    plh.Controls.Add(div)
            '    div.Style.Add("font-size", "smaller")
            '    div.Style.Add("margin-top", "5px")

            '    Dim strong As New HtmlGenericControl("strong")
            '    strong.InnerText = i.UserName & ": "
            '    div.Controls.Add(strong)

            '    Dim span As New Label
            '    span.Text = HttpUtility.HtmlEncode(Framework.CUtilities.Truncate(i.Comment, 200))
            '    span.ToolTip = i.Comment
            '    div.Controls.Add(span)
            'Next

        End Sub
    End Class

End Namespace
